package net.godcode.t5c.mixins;

import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.TapestryConstants;
import org.apache.tapestry.annotations.AfterRender;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.ioc.annotations.Inject;

/**
 * RenderNode handles rendering the DOM node of the component. The node may be
 * a normal (X)HTML element or a text node.
 * 
 * @author Chris Lewis Jan 3, 2008 <chris@thegodcode.net>
 * @version $Id: RenderNode.java 85 2008-01-03 21:53:46Z burningodzilla $
 */
public class RenderNode {
	
	/** A flag showing if the component body will render within an element or as a text node. */
	@Parameter(value = "false", defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX)
	private boolean textNode;
	
	@Inject
	private ComponentResources resources;
	
	@BeginRender
	void beginRender(MarkupWriter writer) {
		if(! textNode) {
			writer.element(resources.getElementName());
		}
	}
	
	@AfterRender
	void afterRender(MarkupWriter writer) {
		if(! textNode) {
			writer.end();
		}
	}
	
}